﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class ProductsDAL
    {
        public DataTable SelectProductsCategory()
        {
            string sql = "select * from CategoryInfo where DelFlag = 0";

            return SQLiteHelper.ExecuteFill(sql);
        }

        public DataTable SelectProductsInfo()
        {
            string sql = "select * from ProductInfo where DelFlag = 0";

            return SQLiteHelper.ExecuteFill(sql);
        }

        public DataTable SelectProductsInfoByID(int id)
        {
            string sql = "select * from ProductInfo where DelFlag = 0 and catid = @catid";
            
            SQLiteParameter[] sQLiteParameters = new SQLiteParameter[]
            {
                new SQLiteParameter("@catid", id)
            };
            return SQLiteHelper.ExecuteFill(sql, sQLiteParameters);
        }

        public int UpdateCategory(string sql, SQLiteParameter[] sQLiteParameters)
        {
            return SQLiteHelper.ExecuteNonQuery(sql, sQLiteParameters);
        }

        //商品名模糊查询
        public DataTable SeleceProductsInfoByLike(string name)
        {
            string sql = "select * from ProductInfo where DelFlag = 0 and proname like @proname";
            SQLiteParameter[] sQLiteParameters = new SQLiteParameter[]
            {
                new SQLiteParameter("@proname", "%" + name +"%")
            };

            return SQLiteHelper.ExecuteFill(sql, sQLiteParameters);
        }
    }
}
